import React, { useEffect, useState } from 'react'

export default function Test() {
  const [count, setCount] = useState(10)
  useEffect(() => {
    let timer = null
    // 开启定时器的操作我只想走一次就够啦，所以第二个参数务必是一个空数组
    timer = setInterval(() => {
      console.log('~~~~')
      setCount((count) => count - 1)
    }, 1000)
    return () => {
      // 清理函数
      clearInterval(timer)
    }
  }, [])
  return <div>Test: {count}</div>
}
